package com.lucy.wx.miniapp.core;

import com.dtflys.forest.Forest;
import com.dtflys.forest.annotation.Get;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@AllArgsConstructor
public class DefaultMiniAppApiImpl implements MiniAppApi{
    @Override
    public String exToken(String appId, String appSecret) {
        String res = Forest.get("https://api.weixin.qq.com/cgi-bin/token")
                .addQuery("grant_type","client_credential")
                .addQuery("appid",appId)
                .addQuery("secret",appSecret)
                .execute(String.class);
        return res;
    }

    @Override
    public String exOpenId(String appId, String appSecret, String code) {
        String res = Forest.get("https://api.weixin.qq.com/sns/jscode2session")
                .addQuery("grant_type","authorization_code")
                .addQuery("appid",appId)
                .addQuery("secret",appSecret)
                .addQuery("js_code",code)
                .execute(String.class);
        return res;
    }

    @Override
    public String wxPublish() {
        return null;
    }
}
